import {
	defineStore
} from 'pinia';
export const useAddressStore = defineStore('address', {
	state: () => {
		return {
			List: [{
					id: 0,
					name: '王贵',
					phone: '18225517585',
					email: '15551245@qq.com',
					path: '',
					province: '安徽省',
					city: '合肥市',
					district: '新站区',
					address: '华润熙云府5#502',
					default: 1
				},
				{
					id: 1,
					name: '安娜',
					phone: '18985623589',
					email: '3596852455@qq.com',
					path: '',
					province: '安徽省',
					city: '合肥市',
					district: '高新区',
					address: '保利梧桐语6#703',
					default: 0
				}
			]
		};
	},

	getters: {

	},
	actions: {
		//编辑
		editRuleForm({
			index,
			item
		}) {
			console.log('3222222222222', index, item);
			if (item.default == 1) {
				this.List.forEach(v => {
					v.default = 0
				})
				item.default = 1
				this.List[index] = item
			}else {
				
				this.List[index] = item
				item.default = 0
			}
			
		},
		//新增
		addRuleForm(payload) {
			if (payload.default == 1) {
				this.List.forEach(v => {
					v.default = 0
				})
				payload.default = 1
			}
			this.List.unshift(payload)
		},

		//删除
		delRuleForm(payload) {
			uni.showModal({
				title: '提示',
				content: '您确定要删除吗',
				success: (res) => {
					if (res.confirm) {
						this.List.splice(payload, 1)
					} else if (res.cancel) {
						console.log('用户点击取消');
					}
				}
			});


		}
	},
});